package com.haoxi.gateway.test.message;

import com.haoxi.gateway.test.SGIPConstant;
import com.haoxi.gateway.test.util.TypeConvert;

public class SGIPSubmitRepMessage extends SGIPMessage {

    public SGIPSubmitRepMessage(byte[] seqid, int result)
            throws IllegalArgumentException {
        if (result < 0 || result > 255) {
            throw new IllegalArgumentException(String.valueOf(String
                    .valueOf((new StringBuffer(String.valueOf(String
                            .valueOf(SGIPConstant.DELIVER_REPINPUT_ERROR))))
                            .append(":result").append(
                                    SGIPConstant.INT_SCOPE_ERROR))));
        } else {
            int len = 29;
            buf = new byte[len];
            TypeConvert.int2byte(len, buf, 0);
            TypeConvert.int2byte(SGIPConstant.Submit_Rep_Command_Id, buf, 4);
            System.arraycopy(seqid, 0, buf, 8, 12);
            buf[20] = (byte) result;
        }
    }

    public int getResult() {
        int tmpId = buf[20];
        return tmpId;
    }

    public int getMsgLength() {
        message_Length = TypeConvert.byte2int(super.buf, 0);
        return message_Length;

    }

    public int getTime_Stamp() {
        time_Stamp = TypeConvert.byte2int(super.buf, 12);
        return time_Stamp;
    }

    public int getSequence_Id() {
        sequence_Id = TypeConvert.byte2int(super.buf, 16);
        return sequence_Id;
    }

    public int getSrcNodeId() {
        src_node_Id = TypeConvert.byte2int(super.buf, 8);
        return src_node_Id;
    }

    public String toString() {

        
        String tmpStr = "SGIP_SUBMIT_REP: ";
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr))))
                .append("\r\nmessage_Length=").append(getMsgLength())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nCommandId=")
                .append(getCommandId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nSrcNodeId=")
                .append(getSrcNodeId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nTime_Stamp=")
                .append(getTime_Stamp())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nSequence_Id=")
                .append(getSequenceId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nResult=")
                .append(getResult())));
        return tmpStr;
    }

    public int getCommandId() {
        return TypeConvert.byte2int(super.buf, 4);
    }
}
